//
//  LZQ_MJRefreshHeader.swift
//  SwiftExercise
//
//  Created by King on 2021/6/18.
//

import UIKit

extension UIScrollView {
    var sHead: MJRefreshHeader {
        get { return mj_header! }
        set { mj_header = newValue }
    }
    
    var sFoot: MJRefreshFooter {
        get { return mj_footer! }
        set { mj_footer = newValue }
    }
}

class LZQ_MJRefreshHeader: MJRefreshGifHeader {

    override func prepare() {
        super.prepare()
        var idaImages = [UIImage]()
        for i in 1...8 {
            let image = UIImage(named: "loading_gif-\(i)")
            idaImages.append(image!)
        }
        self.setImages(idaImages, for: .idle)
        
        var refreshImages = [UIImage]()
        for i in 1...8 {
            let image = UIImage(named: "loading_gif-\(i)")
            refreshImages.append(image!)
        }
        self.setImages(refreshImages, for: .pulling)
        
        self.setImages(refreshImages, for: .refreshing)
        
        //隐藏文字
        lastUpdatedTimeLabel!.isHidden = true
        stateLabel!.isHidden = true
    }
}
class LZQ_RefreshAutoHeader: MJRefreshHeader {}

class LZQ_RefreshFooter: MJRefreshBackNormalFooter {}

class LZQ_RefreshAutoFooter: MJRefreshAutoFooter {}


class LZQ_RefreshDiscoverFooter: MJRefreshBackGifFooter {
    
    override func prepare() {
        super.prepare()
//        backgroundColor = kBackViewColor
        setImages([UIImage(named: "refresh_discover")!], for: .idle)
        stateLabel!.isHidden = true
        refreshingBlock = { self.endRefreshing() }
    }
}

class LZQ_RefreshTipKissFooter: MJRefreshBackFooter {
    
    lazy var tipLabel: UILabel = {
        let tl = UILabel()
        tl.textAlignment = .center
        tl.textColor = UIColor.lightGray
        tl.font = UIFont.systemFont(ofSize: 14)
        tl.numberOfLines = 0
        return tl
    }()
    
    lazy var imageView: UIImageView = {
        let iw = UIImageView()
        iw.image = UIImage(named: "refresh_kiss")
        return iw
    }()
    
    override func prepare() {
        super.prepare()
//        backgroundColor = kBackViewColor
        mj_h = 240
        addSubview(tipLabel)
        addSubview(imageView)
    }
    
    override func placeSubviews() {
        tipLabel.frame = CGRect(x: 0, y: 40, width: bounds.width, height: 60)
        imageView.frame = CGRect(x: (bounds.width - 80 ) / 2, y: 110, width: 80, height: 80)
    }
    
    convenience init(with tip: String) {
        self.init()
        refreshingBlock = { self.endRefreshing() }
        tipLabel.text = tip
    }
}
